<?php
namespace ChannelThrift\Service;

use \Common\Org\PhpRedis;
use \Services\BailService\InvalidException;
use \ChannelThrift\Processor\BailService;

class BidCacheService
{
    const BIDING = 3;//投标中*-
    const BIDDING = 4;//竞标中
    const CACHE_LIFE = 86400;//缓存有效期


    protected static $redis = false;
    private $exceptionCode = array();

    /* 
    拍单出价缓存,缓存时间72小时,包括出价车商列表    
    [
        {order_id:'拍单号',bid_best_price:'投标最高价',bid_best_dealer_id:'投标最高价车商',bidding_best_price:'竞标最高价',bidding_best_dealer_id:'竞标最高价车商',status:'拍单状态'}
        ,[冻结车商id1,冻结车商id2,..冻结车商idn]
    ]
    */
    private $orderSummaryCacheKey = 'AuctionWeaver:OrderBid:Summary:SpecVar:';
    //拍单出价队列
    private $bidQueueKey = 'AuctionWeaver:OrderBid:Queue';    
    //保证金配置
    private $bailConfigInfo = null;

    public function __construct()
    {
        if (!self::$redis) {
            self::$redis=new PhpRedis(0);
        }
        $this->exceptionCode = C('EXCEPTION_CODE') +  C('BAIL_EXCEPTION_CODE');  
    }

    /**
     * 检查车商资格是否符合出价规则
     * @param  int $dealerId 车商 ID
     * @return true/throw
     */
    private function chkDealer($dealerId)
    {
        //检查车商资格
        $carDealerService = new CarDealerService();
        $dealerInfo = $carDealerService->getCarDealer($dealerId);
        if(empty($dealerInfo))
        {
            \Think\Log::record('投标出价——>获取蚁巢车商账号失败 dealerId:'.$dealerId." ");
            throw new InvalidException(array('code' => 360011, 'message' => $this->exceptionCode[360011]));
        }

        if($dealerInfo['status']==0)
        {
            \Think\Log::record('投标出价——>账号已禁用 dealerId:'.$dealerId.' '.var_export($dealerInfo,true));
            throw new InvalidException(array('code' => 130006, 'message' => $this->exceptionCode[130006]));
        }elseif($dealerInfo['level']==0){
            \Think\Log::record('投标出价——>初级买家不能出价, dealerId:'.$dealerId);
            throw new InvalidException(array('code' => 360012, 'message' => $this->exceptionCode[360012]));
        }

        if ($dealerInfo['bail_amount']<$this->getPermitFreezeAmount()){
            \Think\Log::record('竞标出价——>保证金不足，不可以出价, dealerId:'.$dealerId);
            throw new InvalidException(array('code' => 500051, 'message' => $this->exceptionCode[500051]));
        }
    }   

    /**
     * 返回保证金许可冻结金额
     * @return float 保证金许可冻结金额
     */
    private function getPermitFreezeAmount()
    {
        //获取许可冻结保证金金额
        if(!$this->bailConfigInfo){
            $sysConfServ = new SystemConfService();
            $bailInfo = $sysConfServ->getConfByName('BAIL');
            $this->bailConfigInfo = $bailInfo;
        }
        return $this->bailConfigInfo['value'];
    }

    /**
     * 从缓存中获取拍单信息
     * @param  orderId int 拍单ID
     * @return array/throw
     */
    private function getOrderInfoFromCache($orderId){
        if (!$orderId) {
            throw new InvalidException(array('code' => 10003, 'message' => $this->exceptionCode[10003]));   
        }
        $cacheKey=$this->orderSummaryCacheKey.$orderId;
        $info = self::$redis->get($cacheKey);        
        if (!$info) {
            //获得拍单信息
            $orderServ = new OrderService();
            $orderInfo = $orderServ->getOrder($orderId);
            if (!$orderInfo) {
                \Think\Log::record('缓存获取拍单出价信息失败, orderId:'.$orderId);
                throw new InvalidException(array('code' => 0014, 'message' => $this->exceptionCode[0014]));   
            }
            //$orderInfo = array_intersect($orderInfo,array('order_id','order_no'));

            //获得冻结车商列表
            $dealers  = D("ChannelThrift/Aums/DealerBailLog")->field("bl_id,dealer_id,occur_money")->where("order_id='".$orderId."' and is_free=0 and use_type=2")->select();
            $freezeDealerIds = array();
            foreach($dealers as $key=>$val){
                $freezeDealerIds[$val['dealer_id']] = $val;
            }
            $orderInfo['freeze_dealers'] = $freezeDealerIds;

            $ok = self::$redis->set($cacheKey,json_encode($orderInfo,true),self::CACHE_LIFE);
            $info = self::$redis->get($cacheKey);
        }

        $return = json_decode($info,true);
        return $return;
    }

    /**
     * 检查拍单状态
     * @param  array $orderInfo 函数getOrderInfoFromCache的结果
     * @param  int $status  需要检查的拍单状态 [self::BIDDING,self::BIDING]
     * @return void/throw
     */
    private function chkOrderStatus(&$orderInfo,$status=self::BIDDING){

        if ($orderInfo['status'] != $status) {
            if (self::BIDING){
                //不在投标中
                throw new InvalidException(array('code' => 700041, 'message' =>  $this->exceptionCode[700041]));
            } elseif (self::BIDDING){
                //不在竞标中
                throw new InvalidException(array('code' => 700009, 'message' => $this->exceptionCode[700009]));
            }
        }
    }

    /**
     * 检查投标出价
     * @param  array $orderInfo 函数getOrderInfoFromCache的结果
     * @param  price float 出价
     * @return void/throw
     */
    private function chkBidPrice(&$orderInfo,$price){
        if(empty($price)){
            throw new InvalidException(array('code' => 700049, 'message' => $this->exceptionCode[700049]));
        }elseif(strlen(abs($price)) > 7){
            throw new InvalidException(array('code' => 700051, 'message' => $this->exceptionCode[700051]));
        }elseif($price%100!=0){
            throw new InvalidException(array('code' => 700050, 'message' => $this->exceptionCode[700050]));
        }

        if ($price <= $orderInfo['bid_start_price']) {
            //低于起拍价
            throw new InvalidException(array('code' => 700007, 'message' => $this->exceptionCode[700007]));
        }
        if (($price) > ($orderInfo['reserve_price'] * 1.2)) {
            //出价超高
            throw new InvalidException(array('code' => 700033, 'message' => $this->exceptionCode[700033]));
        }
    }

    /**
     * 检查竞标出价
     * @param  array &$orderInfo 拍单信息
     * @param  float $price    出价
     * @return void/throw
     */
    private function chkBiddingPrice(&$orderInfo,$price){
        $this->chkBidPrice($orderInfo,$price);        
        $bidding_best_price = $orderInfo['bidding_best_price'];        
        $diff_price = $price-$bidding_best_price;
        if($diff_price<=0){
            //当前价已更新，您的加价幅度小于300元，请重新出价！
            throw new InvalidException(array('code' => 700047, 'message' => $this->exceptionCode[700047]));
        }elseif($diff_price>0 && $diff_price<300){
            throw new InvalidException(array('code' => 700048, 'message' => $this->exceptionCode[700048]));
        }
    }

    /**
     * 投标参数基础检查
     * @param  int $dealerId 车商Id
     * @param  int $orderId 拍单Id
     * @param  float $price 出价
     * @param  int $devType 登录设备类型[0 web 1 android 2 ios]
     * @return void/throw
     */
    private function chkBidParam($dealerId,$orderId,$price,$devType=0){
        //基本数据验证        
        if (empty($dealerId)) {
            throw new InvalidException(array('code' => 500001, 'message' => $this->exceptionCode[500001]));
        }
        if (empty($orderId)) {
            throw new InvalidException(array('code' => 700002, 'message' => $this->exceptionCode[700002]));
        }
        if (empty($price)) {
            throw new InvalidException(array('code' => 700005, 'message' => $this->exceptionCode[700005]));
        }
    }


    /**
     * 冻结车商出价保证金
     * @param  array $orderInfo 函数getOrderInfoFromCache的结果
     * @param  int $dealerId 车商id
     * @return void/throw
     */
    private function freezeBail(&$orderInfo,$dealerId){
        //获得冻结的ids
        $orderId = $orderInfo['order_id'];
        $freezeInfos = isset($orderInfo['freeze_dealers'])?$orderInfo['freeze_dealers']:false;
        $freezeInfo = isset($freezeInfos[$dealerId])?$freezeInfos[$dealerId]:false;        

        if (!$freezeInfo){
            //冻结当前车商保证金
            $freezeBail = $this->getPermitFreezeAmount();
            $bailService = new BailService();
            $result = $bailService->freezeBail($dealerId,$freezeBail,$orderId);
            if($result->code!='000000'){
                \Think\Log::record('order_id:'.$orderId.',冻结车商'.$dealerId.'保证金失败。');
                throw new InvalidException(array('code' => $result->code, 'message' => $result->message));//-1异常错误（默认）
            }
            //更新出价保证金信息缓存            
            $orderInfo['freeze_dealers'][$dealerId]=array('bl_id'=>0,'dealer_id'=>$dealerId,'occur_money'=>$freezeBail);
            $cacheKey=$this->orderSummaryCacheKey.$orderId;
            $ok = self::$redis->set($cacheKey,json_encode($orderInfo,true),self::CACHE_LIFE);
        }
    }

    /**
     * 解冻"非$ex_dealer_id车商"的拍单冻结保证金
     * @param  array $orderInfo 函数getOrderInfoFromCache的结果
     * @param  int $ex_dealer_id 排除dealer_id
     * @return void/throw
     */
    private function unFreezeOrderBail(&$orderInfo,$ex_dealer_id=0){
        $orderId = $orderInfo['order_id'];
        $freezeInfos = isset($orderInfo['freeze_dealers'])?$orderInfo['freeze_dealers']:array();

        $unFreezeDealerIds = array();
        foreach ($freezeInfos as $freeze) {
            if (isset($freeze['dealer_id'])&&($freeze['dealer_id']!=$ex_dealer_id)) {
                $unFreezeDealerIds[] = $freeze['dealer_id'];    
            }
        }
               
        if(count($unFreezeDealerIds)>0){
            //批量执行解冻
            $unFreezeDealerIdsStr = implode(',',$unFreezeDealerIds); 
            $bailService = new BailService();
            $result = $bailService->unfreezeBail($unFreezeDealerIdsStr,$orderId);

            if($result->code!='000000'){
                \Think\Log::record('order_id:'.$orderId.',dealer_ids:'.$unFreezeDealerIdsStr.' 解冻保证金失败。');
                throw new InvalidException(array('code' => $result->code, 'message' => $result->message));//-1异常错误（默认）
            }

            //更新出价保证金信息缓存
            foreach ($unFreezeDealerIds as $dealerId) {
                unset($orderInfo['freeze_dealers'][$dealerId]);
            }
            $cacheKey=$this->orderSummaryCacheKey.$orderId;
            $ok = self::$redis->set($cacheKey,json_encode($orderInfo,true),self::CACHE_LIFE);
        }
    }


    public function test(){
        $orderId = 2521;
        $price =  14400;
        $orderInfo = $this->getOrderInfoFromCache($orderId);
        $this->chkBiddingPrice($orderInfo,$price);
        /*$this->freezeBail($orderInfo,467);
        $orderInfo = $this->getOrderInfoFromCache($orderId);print_r($orderInfo['freeze_dealers']);
        $this->unFreezeOrderBail($orderInfo,243);
        $orderInfo = $this->getOrderInfoFromCache($orderId);print_r($orderInfo['freeze_dealers']);*/

        // print_r($orderInfo);
        // $this->freezeBail(2521,467);
        //$t = $this->chkBidParam(467,2521,10);
        //$t = $this->getOrderInfoFromCache(2521);
        // $t = $this->chkDealer(63);
        // print_r($t);
        

        /*$this->bid(467,$orderId,25000);
        $this->bid(468,$orderId,26000);
        $this->bid(469,$orderId,27000);
        $this->bid(469,$orderId,25000);
        $this->bid(470,$orderId,27000);*/
        
        //$this->startBidding($orderId);
    }    

    /**
     * 投标出价
     * @param  int  $dealerId 车商号
     * @param  int  $orderId  拍单号
     * @param  float  $price    投标出价
     * @param  integer $devType 登录设备类型[0 web 1 android 2 ios]
     * @return void/throw
     */
    public function Bid($dealerId,$orderId,$price,$devType=0){
        //检查输入
        $this->chkBidParam($dealerId,$orderId,$price,$devType);
        //获得拍单信息
        $orderInfo = $this->getOrderInfoFromCache($orderId);
        //检查拍单状态
        $this->chkOrderStatus($orderInfo,self::BIDING);
        //检查出价
        $this->chkBidPrice($orderInfo,$price);
        //检查车商资格
        $this->chkDealer($dealerId);

        $data = array();
        $data['order_id'] = $orderId;
        $data['dealer_id'] = $dealerId;
        $data['price'] = $price;
        $data['createtime'] = date('Y-m-d H:i:s');
        $data['dev_type'] = $devType;
        $data['bid_type'] = 'bid';

        //出价入队
        $appendLen = self::$redis->lPush($this->bidQueueKey,json_encode($data,true));
    }


    /**
     * 生成投标阶段最高价和车商
     * @param  int $orderId 拍单ID
     * @return array(
                    [order_id] => 2521
                    [dealer_id] => 469
                    [price] => 27000
                    [createtime] => 2017-04-25 18:28:43
                    [dev_type] => 0
                    [bid_type] => bid
                )

     */
    private function genBidTopPrice($orderId){
        //从缓存获得
        $bidList = self::$redis->lRange($this->bidQueueKey,0,-1);
        //找出最高价
        $best = array();
        if (isset($bidList[0])) {
            $best = json_decode($bidList[0],true);                        
            foreach ($bidList as $bidInfo) {
                $bidInfo = json_decode($bidInfo,true);                
                if ($bidInfo['price']>=$best['price'] && $bidInfo['dealer_id']!=$best['dealer_id']) {
                    $best = $bidInfo;
                }
            }
        }
        //写入投标阶段最高价
        $data['bid_best_price']=$best['price'];
        $data['bid_best_dealer_id']=$best['dealer_id'];
        $data['last_time']=date('Y-m-d H:i:s');
        $orderModel = D('ChannelThrift/Aums/Order');
        $orderModel->where("`order_id`='$orderId' ")->save($data);
        return $best;
    }

    /**
     * 结束拍单，插入车源和拍单状态log
     * @param  array $orderInfo 函数getOrderInfoFromCache的结果
     * @return void/throw
     */
    private function upOrderTraceLog(&$orderInfo){
        $now = microtime_time();
        //更新拍单跟踪log
        $orderLogModel = D('ChannelThrift/Aums/OrderTraceLogList');
        $data = array();
        $data['order_id'] = $orderInfo['order_id'];
        $data['car_id'] = $orderInfo['car_id'];
        $data['emp_name'] = '--';
        $data['action_no'] = 1008;
        $data['action_name'] = '竞拍结束';
        $data['createtime'] = $now;
        $orderLogModel->fetchSql(true)->add($data);

        //更新车源跟踪log
        $carModel = D('ChannelThrift/Aums/Car');
        $carInfo = $carModel->where("`car_id`='".$orderInfo['car_id']."'")->fetchOne();    
        $carLogModel = D('ChannelThrift/Aums/CarTraceLogList');        
        $data = array();
        $data['owner_id'] = $carInfo['owner_id'];
        $data['car_id'] = $orderInfo['car_id'];
        $data['emp_name'] = '--';
        $data['action_no'] = 1014;
        $data['action_name'] = '竞拍结束';
        $data['createtime'] = $now;
        $carLogModel->fetchSql(true)->add($data);
    }

    /**
     * 更新车源状态为待确认
     * @param  array $orderInfo 函数getOrderInfoFromCache的结果
     * @return void/throw
     */
    private function upCarSourceWaitConfirm(&$orderInfo){
        //更新车源状态为待确认
        $carModel = D('ChannelThrift/Aums/Car');
        $carInfo = $carModel->where("`car_id`='".$orderInfo['car_id']."'")->fetchOne(); 

        $carSourceModel = D('ChannelThrift/Aums/CarSource');
        $carSourceInfo = $carSourceModel->where("`sid`='".$carInfo['car_id']."'")->fetchOne(); 

        $data = array();
        $data['status'] = 300;        
        if($carSourceInfo['status']==200){
            $carSourceModel->where("`sid`='".$carSourceInfo['sid']."'")->save($data);
        }
    }

    /**
     * 清除拍单机器人出价redis
     * @param  int $orderId 拍单号
     * @return void/throw
     */
    private function cleanIntelBid($orderId){
        $redis = self::$redis;
        $redis->srem('autobidding_order_list',$orderId);
        $redis->del('autobidding_dealer_list_'.$orderId);//删除所有设置智能出价的车商
        $keys = $redis->keys('autobidding_dealer_info_'.$orderId.'_*');
        if($keys){
            foreach($keys as $v){
                $redis->del($v);
            }
        }
        $redis->del('autobidding_order_info_'.$orderId);
        $redis->del('autobidding_order_bidding_'.$orderId);
    }

    /**
     * 更新交易服务费
     * @param  array $orderInfo 函数getOrderInfoFromCache的结果
     * @return void/throw
     */
    private function updateCommision(&$orderInfo)
    {
        if($orderInfo['bidding_best_price'] > $orderInfo['bid_best_price']){
            $best_price = $orderInfo['bidding_best_price'];
            $success_dealer_id = $orderInfo['bidding_best_dealer_id'];
        }else{
            $best_price = $orderInfo['bid_best_price'];
            $success_dealer_id = $orderInfo['bid_best_dealer_id'];
        }
        $commision = $this->getCommision($best_price);

        //写redis
        $orderId = $orderInfo['order_id'];
        $orderInfo['success_price'] = $best_price ;
        $orderInfo['success_dealer_id'] = $success_dealer_id ;
        $orderInfo['commision'] = $commision ;
        $cacheKey=$this->orderSummaryCacheKey.$orderId;
        $ok = self::$redis->set($cacheKey,json_encode($orderInfo,true),self::CACHE_LIFE);
        //写mysql
        $orderModel = D('ChannelThrift/Aums/Order');
        $data = array();
        $data['success_price'] = $best_price ;
        $data['success_dealer_id'] = $success_dealer_id ;
        $data['commision'] = $commision ;
        $orderModel->fetchSql(true)->where("`order_id`=$orderId")->save($data); 
    }

    /**
     * 计算交易服务费
     * @param int $price 初始价格
     * @return int $p 交易服务费
     */
    private function getCommision($price)
    {
        $settingModel = D('ChannelThrift/Aums/Setting');
        $map['name'] = array('in',array('COMMISION_MIN_FEE','COMMISION_MAX_FEE','COMMISION_PERCENTAGE'));
        $rows = $settingModel->where($map)->select();
        $config = array();
        foreach ($rows as $row) {
                $config[$row['name']] = $row['value'];
        }
        $min_fee = intval($config['COMMISION_MIN_FEE']);        
        $max_fee = intval($config['COMMISION_MAX_FEE']);
        $percentage = floatval($config['COMMISION_PERCENTAGE']);

        $p = $price * $percentage;
        if ($p <= $min_fee) {
            $p = $min_fee;
        } elseif ($p >= $max_fee) {
            $p = $max_fee;
        } else {
            $p = round($p / 100) * 100;
        }
        return $p;
    }

    /**
     * 开始竞拍
     * @param  int $orderId 拍单号
     * @return void/throw
     */
    public function StartBidding($orderId){
        $bidBest=$this->genBidTopPrice($orderId);
        //获得拍单信息
        $orderInfo = $this->getOrderInfoFromCache($orderId);
        $this->unFreezeOrderBail($orderInfo,(isset($bidBest['dealer_id'])?$bidBest['dealer_id']:0));

        //更改拍单状态为竞拍
        $orderModel = D('ChannelThrift/Aums/Order');
        $orderModel->where("`order_id`='$orderId' ")->save(array('status'=>self::BIDING));
    }

    /**
     * 结束拍单
     * @param  int $orderId 拍单Id
     * @return void/throw
     */
    public function EndBidding($orderId){
        $lock_key = "bidding_".$id."_lock";
        //获取结束锁
        $r = $redis->lock_wait($lock_key,60);
        if($r){
            $orderInfo = $this->getOrderInfoFromCache($orderId);
            //拍单结束
            //写redis
            $orderInfo['status'] = 5;            
            $cacheKey=$this->orderSummaryCacheKey.$orderId;
            $ok = self::$redis->set($cacheKey,json_encode($orderInfo,true),self::CACHE_LIFE);
            //写mysql
            $orderModel = D('ChannelThrift/Aums/Order');
            $data = array();
            $data['status'] = 5;
            $now = date('Y-m-d H:i:s');
            $data['last_time'] = $now;
            $data['bidding_end_time'] = $now;            
            $orderModel->fetchSql(true)->where("`order_id`=$orderId")->save($data);            

            //解冻未中标者保证金            
            $ex_dealer_id = 0;
            if ($orderInfo['bid_best_price']>=$orderInfo['bidding_best_price']) {
                $ex_dealer_id = $orderInfo['bid_best_dealer_id'];
            } else {
                $ex_dealer_id = $orderInfo['bidding_best_dealer_id'];
            }
            $this->unFreezeDealerIds($orderInfo,$ex_dealer_id);

            //插入车源和拍单状态变更记录
            $this->upOrderTraceLog($orderInfo);
            //更新车源状态为待确认
            $this->upCarSourceWaitConfirm($orderInfo);
            //更新交易费
            $this->updateCommision($orderInfo);

            //释放结束锁
            $redis->unlock($lock_key);

            //删除智能出价相关redis 队列
            $this->cleanIntelBid($orderInfo['order_id']);
        }
    }

    /**
     * 设置竞拍场开始
     * @param  int $sceneId 场Id
     * @return void/throw
     */
    public function StartScene($sceneId){
        $sceneModel = D('ChannelThrift/Aums/Scene');
        $sceneModel->where("`scene_id`='$sceneId'")->save(array('status'=>2));
    }

    /**
     * 设置竞拍场结束
     * @param  int $sceneId 场Id
     * @return void/throw
     */
    public function EndScene($sceneId){
        $sceneModel = D('ChannelThrift/Aums/Scene');
        $data = array();
        $data['status'] = 3;
        $data['endtime'] = date('Y-m-d H:i:s');
        $sceneModel->where("`scene_id`='$sceneId'")->save($data);
    }

    /**
     * 检查结束锁出价许可
     * @param  int $orderId 拍单号
     * @return boolean void/throw
     */
    private function chkEndLockPermit($orderId){
        $lockKey = "bidding_".$orderId."_lock";
        if(self::$redis->exists($lockKey)){
            throw new InvalidException(array('code' => 700045, 'message' => $this->exceptionCode[700045]));
        }
    }

    /**
     * 检查车商1秒内出价许可
     * @param  int $dealerId 车商号
     * @return void/throw
     */
    private function chkInSecond($dealerId){
        $ulock_key = 'bidding_limit1_lock_'.$dealerId;
        $ulock_key1 = 'bidding_limit1_lock2_'.$dealerId;
        //------------防止1秒内连续出价
        if(!$this->redis->lock($ulock_key)){
            //发生异常，抛出异常提示
            throw new InvalidException(array('code' => 700044, 'message' => $this->exceptionCode[700044]));
        }
        if($this->redis->exists($ulock_key1)){
            $this->redis->unlock($ulock_key);
            //发生异常，抛出异常提示
            throw new InvalidException(array('code' => 700044, 'message' => $this->exceptionCode[700044]));
        }
        $this->redis->set($ulock_key1,$dealerId,1);
        $this->redis->unlock($ulock_key);
    }

    /**
     * 竞标出价
     * @param int  $dealerId 车商号
     * @param int  $orderId  拍单号
     * @param float  $orgPrice 原价
     * @param float  $addPrice 加价
     * @param integer $devType 登录设备类型[0 web 1 android 2 ios]
     * @param integer $isAuto   是否机器出价
     */
    public function Bidding($dealerId,$orderId,$orgPrice,$addPrice,$devType=0,$isAuto=0){
        //出价参数基本检查
        $this->chkBidParam($dealerId,$orderId,$price,$devType);
    }


    //todo:上拍
    //检查投标
        //todo:出价参数检查#
        //todo:检查拍单状态,是否投标中#
        //todo:检查帐号资格#
        //todo:检查价格是否合法#     
        //todo:保证金是否足够#
    //投标出价
        //todo:冻结保证金#
        //todo:解冻拍单其它车商保证金#        
        //todo:入队出价#
        //todo:开始竞拍#       
    //todo:计算投标阶段的第一名#
    //------------------------------------GO
        //todo:出队出价入库 GO
        //todo:生成投标出价记录入库
        //todo:更新车商操作日志,参考：DealerLogService.InsertDealerLog
        //todo:更新"车商出价的车"表,参考:CarDealerService.dealerBidPrice方法
    

    //检查竞标
        //todo:出价参数检查#
        //todo:检查结束锁#
        //todo:防止1秒内连续出价#
        //todo:检查帐号资格#
        //todo:保证金是否足够#
        //todo:检查拍单状态，是否竞标中#
        //todo:出价超高检查#
        //todo:出价是否以300整数倍，大于基价#
        //todo:超过保留价,不能连接出价,只能交替出价
    //竞标出价
        //todo:拍单基价锁加锁
        //todo:冻结保证金
        //todo:解冻拍单其它车商保证金
        //todo:执行出价入队,剩余10秒内延长30秒竞拍时间,更新出价信息缓存
        //todo:更新车商竞标出价信息缓存
        //todo:清除memcache出价记录
        //todo:socket数据类型转换,PUSH出价信息到redis,通知node监听
        //todo:拍单锁(基价锁)解锁
        //todo:智能报价处理
        //------------------------------------GO
        //todo:出队出价入库GO
        //todo:生库竞标出价记录入库


    
}
